<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="类型" prop="cardType">
        <el-select v-model="queryParams.cardType" placeholder="请选择类型" clearable size="small">
          <el-option label="白银月卡" :value="1" />
          <el-option label="黄金月卡" :value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="用户" prop="userId">
        <el-input v-model="queryParams.userKey" placeholder="请输入用户" clearable size="small" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="userLogCardList">
      <el-table-column label="用户账号" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.userAccount?(scope.row.userAccount.accountName+
            '('+scope.row.userAccount.catCode+')'):'--' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户昵称" align="center" >
        <template slot-scope="scope">
          <span>{{ scope.row.userAccount?scope.row.userAccount.nick:'--' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="类型" align="center" prop="cardType" />
      <el-table-column label="猫粮值" align="center" prop="catFoot" />
      <el-table-column label="购买时间" align="center" prop="expireTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="到期时间" align="center" prop="expireTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expireTime)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" width="180">
        <template slot-scope="scope">
          <span v-if="scope.row.status===1">生效中</span>
          <span v-else-if="scope.row.status===2">已过期</span>
          <span v-else>未知</span>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listUserLogCard } from "@/api/system/userLogCard";

export default {
  name: "UserLogCard",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 用户购买月卡日志表格数据
      userLogCardList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cardType: undefined,
        userKey: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户购买月卡日志列表 */
    getList() {
      this.loading = true;
      listUserLogCard(this.queryParams).then(response => {
        this.userLogCardList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
  }
};
</script>